package com.alorma.bcn.objects;

import com.android.dataframework.Entity;
import com.google.android.maps.GeoPoint;

public class AlertaEntity{

	private int nivel = 0;
	private String codigo = "";
	private String nombre = "";

	private String type = "";
	private String detall = "";
	private GeoPoint punto;
	private Double lat = 0.0;
	private Double lon = 0.0;

	private static String CAMP_CODIGO = "codi";
	private static String CAMP_NOMBRE = "nombre";
	private static String CAMP_LAT = "lat";
	private static String CAMP_LON = "lon";
	private static String CAMP_DETALLE = "detall";
	private static String CAMP_NIVELL = "nivell";
	private static String CAMP_TIPO = "tipo";
	
	public AlertaEntity(int n, String t, String d, Double latx, Double lonx)
	{
		this.nivel = n;
		this.type = t;
		this.detall = d;
		this.lat = latx;
		this.lon = lonx;
		this.lat = this.lat * 1E6;
		this.lon = this.lon * 1E6;
	}
	
	public AlertaEntity() {
		
	}

	public void setNivel(int n)
	{
		this.nivel = n;
	}
	
	public void setType(String t)
	{
		this.type = t;
	}
	
	public void setDetall(String d)
	{
		this.detall = d;
	}
	
	public void setLat(Double l)
	{
		this.lat = l * 1E6;
	}
	
	public void setLon(Double l)
	{
		this.lon = l *1E6;
	}
	
	public void setPunto(Double lat, Double lon)
	{
		this.punto = new GeoPoint(lat.intValue(), lon.intValue());
	}
	
	public AlertaEntity convertFromEntity(Entity ent)
	{
		this.nombre = ent.toString();
		this.nivel = ent.getInt(CAMP_NIVELL);
		Double dlat = Double.parseDouble(ent.getString(CAMP_LAT));
		this.lat = dlat*1E6;
		Double dlon = Double.parseDouble(ent.getString(CAMP_LON));
		this.lon = dlon*1E6;
		
		setPunto(this.lat, this.lon);
		
		this.type = ent.getString(CAMP_TIPO);
		this.detall = ent.getString(CAMP_DETALLE);
		this.codigo = ent.getString(CAMP_CODIGO);
		
		return this;
	}
	
	public String getCodigo()
	{
		return this.codigo;
	}
	
	public String getNombre()
	{
		return this.nombre;
	}
	
	public int getNivel()
	{
		return this.nivel;
	}
	
	public String getType()
	{
		return this.type;
	}
	
	public String getDetall()
	{
		return this.detall;
	}
	
	public String getLat()
	{
		return this.lat.toString();
	}
	
	public String getLon()
	{
		return this.lon.toString();
	}
	
	public String getPuntoString()
	{
		String cadena = "";
		if (this.punto == null)
		{
			this.setPunto(this.lat, this.lon);
		}
		cadena += "Lat: " + Integer.toString(this.punto.getLatitudeE6());
		cadena += " - ";
		cadena += "Lon: " + Integer.toString(this.punto.getLongitudeE6());
		return cadena;
	}
	
	public GeoPoint getPunto()
	{
		if (this.punto == null)
		{
			this.setPunto(this.lat, this.lon);
		}
		return this.punto;
	}
}
